package base64;

import java.lang.reflect.Method;

/**
 * Created with IntelliJ IDEA.
 * User: leep
 * Date: 15-12-31
 * Time: 上午11:37
 * To change this template use File | Settings | File Templates.
 */
public class Base64 {
	public static void main(String[] args) throws Exception {
		String s = "wiOPF0CdLbr3dHZqVK9Jrj-VGLMmp3IDwcvfhT2auaj-cBh4fwt06-sM084LStZG2nWZu4iQ4zOP5vk0fitWnUGEjlDZQJ0MTWzgekXL96usmLBC0Sp-s0aY--OA3R-P2Vn8FrRbGWQITdXp2hgaKIEuWVwmy7g5Aj1pcxqqoxcs1bUiDgLF6h1kkUeR3f3B5aBBiOCPox7I4lCpu4Dsow__";
		System.out.println(encodeBase64(s.getBytes()));
		System.out.println(decodeBase64(s));

	}

	public static String decodeBase64(String input) throws Exception {
		Class clazz = Class.forName("com.sun.org.apache.xerces.internal.impl.dv.util.Base64");
		Method mainMethod = clazz.getMethod("decode", String.class);
		mainMethod.setAccessible(true);
		Object retObj = mainMethod.invoke(null, input);
		byte[] r = (byte[]) retObj;
		String s = new String(r);
		return s;
	}

	public static String encodeBase64(byte[] input) throws Exception {
		Class clazz = Class.forName("com.sun.org.apache.xerces.internal.impl.dv.util.Base64");
		Method mainMethod = clazz.getMethod("encode", byte[].class);
		mainMethod.setAccessible(true);
		Object retObj = mainMethod.invoke(null, new Object[]{input});
		return (String) retObj;
	}
}
